package org.apache.myfaces.orchestra.examples.backings;

import org.apache.myfaces.orchestra.conversation.Conversation;
import org.apache.myfaces.orchestra.examples.model.dao.ItemDao;
import org.apache.myfaces.orchestra.examples.model.po.Item;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public class MaintainItem
{
	private Item currentItem = new Item();

	private ItemDao itemDao;

	public ItemDao getItemDao()
	{
		return itemDao;
	}

	public void setItemDao(ItemDao itemDao)
	{
		this.itemDao = itemDao;
	}

	@Transactional
	public String saveItemAction()
	{
		itemDao.save(currentItem);

		return null;
	}

	@Transactional
	public String newItemAction()
	{
		currentItem = new Item();
		
		return null;
	}

	@Transactional
	public String selectItemAction()
	{
		return null;
	}

	@Transactional
	public String startOverConversationAction()
	{
		Conversation.getCurrentInstance().invalidate();

		return null;
	}

	public List getItems()
	{
		return itemDao.getAll();
	}

	public Item getCurrentItem()
	{
		return currentItem;
	}

	public void setCurrentItem(Item currentItem)
	{
		this.currentItem = currentItem;
	}
}
